Everything Totally Explained


Ask & we'll explain, totally!
Quine (computing)
Totally Explained


  NEW! All the latest news in the worlds of computer gaming, entertainment, the environment,  
finance, health, politics, science, stocks & shares, technology and much, much, more.  


View this entry using RSS

Everything about Quine Computing totally explained

In computing, a quine is a program, a form of metaprogram, that produces its complete source code as its only output. For amusement, programmers sometimes attempt to develop the shortest possible quine in any given programming language. Note that programs that take input are not considered quines. This would allow the source code to be fed to the program via keyboard input, opening the source file of the program, and similar mechanisms. Also, a quine that contains no code is ruled out as trivial; in many programming languages executing such a program will output the code (for example nothing). Such an empty program once won the "worst abuse of the rules" prize in the Obfuscated C contest.
   Quines are named after philosopher Willard Van Orman Quine (1908–2000), who made an extensive study of indirect self-reference. He coined, among others, the following paradox-producing expression, known as Quine's paradox: "'Yields falsehood when preceded by its quotation' yields falsehood when preceded by its quotation." (from http://www.paradoxes.co.uk)

History

A quine exists in any programming language that has the ability to output any computable string, as a direct consequence of Kleene's recursion theorem. The specific idea of quines first appeared in Bratley, Paul and Jean Millo. "Computer Recreations; Self-Reproducing Automata", Software -- Practice & Experience, Vol. 2 (1972). pp. 397-400. Bratley first became interested in self-reproducing programs after seeing the first known such program written in Atlas Autocode at Edinburgh in the 1960s by the University of Edinburgh lecturer and researcher Hamish Dewar. This program appears below:
%BEGIN !THIS IS A SELF-REPRODUCING PROGRAM %ROUTINESPEC R R PRINT SYMBOL(39) R PRINT SYMBOL(39) NEWLINE %CAPTION %END~ %CAPTION %ENDOFPROGRAM~ %ROUTINE R %PRINTTEXT ' %BEGIN !THIS IS A SELF-REPRODUCING PROGRAM %ROUTINESPEC R R PRINT SYMBOL(39) R PRINT SYMBOL(39) NEWLINE %CAPTION %END~ %CAPTION %ENDOFPROGRAM~ %ROUTINE R %PRINTTEXT ' %END %ENDOFPROGRAM

Examples

In general, the method used to create a quine in any programming language is to have, within the program, two pieces: (a) code used to do the actual printing and (b) data that represents the textual form of the code (for example, progdata in the first C example below). The code functions by using the data to print the code (which makes sense since the data represents the textual form of the code), but it also uses the data, processed in a simple way (for example, quote below) to print the textual representation of the data itself. There are many ways the code and the data can be organized together within the program (neither must be contiguous), but a common telltale sign of the data section is that it mirrors some part of the entire program.
   An example in colloquial English would be:
"quoted and followed by itself is a quine." quoted and followed by itself is a quine.
   (from http://spikeypillow.com/item/31)

C

The idea behind this quine is to store a copy of the program code in a string, and use that to print out both the program code and the string. /* A simple quine (self-printing program), in standard C. */
   /* Note: in designing this quine, we've tried to make the code clear * and readable, not concise and obscure as many quines are, so that * the general principle can be made clear at the expense of length. * In a nutshell: use the same data structure (called "progdata" * below) to output the program code (which it represents) and its own * textual representation. */
  1. include
void quote(const char *s) /* This function takes a character string s and prints the * textual representation of s as it might appear formatted * in C code. */ It should be noted that this program uses the printf function without including its corresponding header (#include <stdio.h>), which can result in undefined behavior. Also, the return type declaration for main has been left off to reduce the length of the program.

Scheme (also valid Common Lisp)

This quine works by feeding the program to itself, which then converts the data structure to source code. ((lambda (x) (list x (list 'quote x))) '(lambda (x) (list x (list 'quote x))))

Further Information

Get more info on 'Quine Computing'.


External Link Exchanges

Do you know how hard it is to get a link from a large encyclopaedia? Well we're different and will prove it. To get a link from us just add the following HTML to your site on a relevant page:

    <a href="http://quine__computing.totallyexplained.com">Quine (computing) Totally Explained</a>

Then simply click through this link from your web page. Our crawlers will verify your link, extract the title of your web page and instantly add a link back to it. If you like you can remove the words Totally Explained and embed the link in article text.
   As long as your link remains in place, we'll keep our link to you right here. Please play fair - our crawlers are watching. Your site must be closely related to this one's topic. Any kind of spamming, dubious practises or removing the link will result in your link from us being dropped and, potentially, your whole site being banned.



Copyright © 2007-8 totallyexplained.com | Licensed under the GNU Free Documentation License | Site Map
This article contains text from the Wikipedia article Quine (computing) (History) and is released under the GFDL | RSS Version